package com.swbyte.utils.kotlin

import android.content.ContentResolver
import android.content.pm.PackageManager
import android.content.res.AssetManager
import android.content.res.Resources
import android.graphics.drawable.Drawable
import android.support.annotation.ColorRes
import android.support.annotation.DrawableRes
import android.support.annotation.StringRes
import android.support.v4.app.Fragment
import android.support.v4.content.ContextCompat
import android.widget.Toast
import com.chaodriod.common.utils.ALog
import com.chaodriod.common.utils.ToastUtils
import com.chaodriod.common.utils.Utils

/**
 * Created by CHEN on 2018/3/15.
 */

/**
 * Log
 */
private val Fragment.TAG: String
    get() = javaClass.simpleName

fun Fragment.logd(msg: String) {
    ALog.d(msg)
}

fun Fragment.logi(msg: String) {
    ALog.i(msg)
}

fun Fragment.logw(msg: String) {
    ALog.w(msg)
}

fun Fragment.loge(msg: String) {
    ALog.e(msg)
}

/**
 * Toast
 */
fun Fragment.toast(msg: String) {
    ToastUtils.show(context, msg)
}

fun Fragment.toastLong(msg: String) {
    ToastUtils.show(context, msg, Toast.LENGTH_LONG)
}

/**
 * 获取资源
 */
private val Fragment.resources: Resources
    get() = Utils.getContext().resources

private val Fragment.assets: AssetManager
    get() = Utils.getContext().assets

private val Fragment.contentResolver: ContentResolver
    get() = Utils.getContext().contentResolver

private val Fragment.packageManager: PackageManager
    get() = Utils.getContext().packageManager

private val Fragment.theme: Resources.Theme?
    get() = context?.theme

fun Fragment.getDrawable(@DrawableRes id: Int): Drawable? {
    return ContextCompat.getDrawable(Utils.getContext(), id)
}

fun Fragment.getColor(@ColorRes id: Int): Int {
    return ContextCompat.getColor(Utils.getContext(), id)
}

fun Fragment.getString(@StringRes id: Int): String {
    return Utils.getContext().getString(id)
}

fun Fragment.getText(@StringRes id: Int): CharSequence {
    return Utils.getContext().getText(id)
}


